<template>
  <div class="content">
    <div class="header">
      <el-button type="primary" @click="btnClickDownload">
        下载分析结果
      </el-button>
      <div class="legend">
        <div class="legend-des">图例</div>
        <div class="legend-icon">
          <SvgIcon class="svg-icon" icon="A" />
          <span>A相</span>
          <SvgIcon class="svg-icon" icon="B" />
          <span>B相</span>
          <SvgIcon class="svg-icon" icon="C" />
          <span>C相</span>
          <SvgIcon class="svg-icon" icon="abnormal" />
          <span>异常</span>
        </div>
      </div>
    </div>
    <div class="title">
      <SvgIcon class="electricity-title" icon="electricity-title" />
      <dv-decoration5 :dur="2" style="width: 300px; height: 40px" />
    </div>
    <dv-border-box8 style="width: 100%; height: auto" :dur="5">
      <dv-border-box8
        style="width: 100%; height: auto"
        :reverse="true"
        :dur="5"
      >
        <div class="container-title">
          <div>file_name:{{ route.query.file_name }}</div>
        </div>
        <el-scrollbar height="72vh">
          <div class="container">
            <ResultMainData
              :integrationData="integrationData"
              title="文件一"
            ></ResultMainData>
          </div>
        </el-scrollbar>
      </dv-border-box8>
    </dv-border-box8>
  </div>
</template>

<script setup>
import { onMounted, ref, defineProps } from "vue";
import ResultMainData from "./ResultMainData";
import { postDownload } from "@/api/api";
import { useRoute, useRouter } from "vue-router";
import axios from "axios";
const route = useRoute();
const props = defineProps({
  integrationData: {
    type: Array,
    required: true,
  },
  title: {
    type: String,
    required: true,
  },
});
const electricityData = ref([
  {
    type: "A", // 表示哪一项
    typeName: "A相", // 哪一项的名字
    list: [
      {
        icon: "A", // 表示的图标 （A项，B项，C项）
        name: "张三", // 名称
        type: 1, // 表示的类型 看页面上的 农 商 替
      },
      {
        icon: "A",
        name: "李四",
        type: 2,
      },
      {
        icon: "C",
        name: "王五",
        type: 3,
      },
      {
        icon: "A",
        name: "张三",
        type: 1,
      },
      {
        icon: "A",
        name: "李四",
        type: 2,
      },
      {
        icon: "C",
        name: "王五",
        type: 3,
      },
      {
        icon: "A",
        name: "张三",
        type: 1,
      },
      {
        icon: "A",
        name: "李四",
        type: 2,
      },
      {
        icon: "C",
        name: "王五",
        type: 3,
      },
      {
        icon: "A",
        name: "张三",
        type: 1,
      },
      {
        icon: "A",
        name: "李四",
        type: 2,
      },
      {
        icon: "C",
        name: "王五",
        type: 3,
      },
      {
        icon: "A",
        name: "张三",
        type: 1,
      },
      {
        icon: "A",
        name: "李四",
        type: 2,
      },
      {
        icon: "C",
        name: "王五",
        type: 3,
      },
    ],
  },
  {
    type: "B",
    typeName: "B相",
    list: [
      {
        icon: "C",
        name: "张三",
      },
      {
        icon: "A",
        name: "李四",
      },
      {
        icon: "B",
        name: "王五",
      },
    ],
  },
  {
    type: "C",
    typeName: "C相",
    list: [
      {
        icon: "A",
        name: "张三",
      },
      {
        icon: "B",
        name: "李四",
        type: 1, // 农
      },
      {
        icon: "B",
        name: "王五",
        type: 2, // 替
      },
      {
        icon: "A",
        name: "赵六",
        type: 3, // 商
      },
    ],
  },
  {
    type: "D",
    typeName: "异常",
    list: [
      {
        icon: "abnormal",
        name: "张三",
      },
      {
        icon: "abnormal",
        name: "李四",
      },
      {
        icon: "abnormal",
        name: "王五",
      },
    ],
  },
]);
// 下载分析结果
const btnClickDownload = async () => {
  axios({
    method: "post",
    url: "http://127.0.0.1:8000/app/download",
    data: { file_name: route.query.file_name },
    responseType: "blob",
  }).then((res) => {
    console.log(res);
    let blob = new Blob([res.data], {
      type: "application/vnd.ms-excel",
    });
    let fileName = route.query.file_name + "分析结果" + ".xlsx";
    if (window.navigator.msSaveOrOpenBlob) {
      // console.log(2)
      navigator.msSaveBlob(blob, fileName);
    } else {
      // console.log(3)
      var link = document.createElement("a");
      link.href = window.URL.createObjectURL(blob);
      link.download = fileName;
      link.click();
      //释放内存
      window.URL.revokeObjectURL(link.href);
    }
  });
};
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  height: 100%;
  // background: red;
  .header {
    display: flex;
    justify-content: space-between;
    .legend {
      display: flex;
      align-items: center;
      color: white;
      .legend-des {
        font-weight: bold;
        font-size: 24px;
        margin-right: 10px;
      }
      .legend-icon {
        font-size: 30px;
        span {
          margin: 8px;
          font-size: 20px;
        }
      }
    }
  }
  .title {
    margin: 0 auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .electricity-title {
      font-size: 60px;
    }
  }
  .container-title {
    display: flex;
    justify-content: space-around;
    line-height: 50px;
  }
  .container {
    width: 96%;
    display: flex;
    justify-content: space-around;
    padding: 0px 20px 20px 20px;
  }
}
</style>
